package com.jianbing.shasha.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.shasha.domain.ShashaStudy;
import com.jianbing.shasha.service.IShashaStudyService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 各关学习内容Controller
 * 
 * @author ruoyi
 * @date 2024-06-09
 */
@RestController
@RequestMapping("/shasha/study")
public class ShashaStudyController extends BaseController
{
    @Autowired
    private IShashaStudyService shashaStudyService;

    /**
     * 查询各关学习内容列表
     */
    // @PreAuthorize("@ss.hasPermi('shasha:study:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShashaStudy shashaStudy)
    {
        startPage();
        List<ShashaStudy> list = shashaStudyService.selectShashaStudyList(shashaStudy);
        return getDataTable(list);
    }

    /**
     * 导出各关学习内容列表
     */
    //   @PreAuthorize("@ss.hasPermi('shasha:study:export')")
    @Log(title = "各关学习内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShashaStudy shashaStudy)
    {
        List<ShashaStudy> list = shashaStudyService.selectShashaStudyList(shashaStudy);
        ExcelUtil<ShashaStudy> util = new ExcelUtil<ShashaStudy>(ShashaStudy.class);
        util.exportExcel(response, list, "各关学习内容数据");
    }

    /**
     * 获取各关学习内容详细信息
     */
    //   @PreAuthorize("@ss.hasPermi('shasha:study:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shashaStudyService.selectShashaStudyById(id));
    }

    /**
     * 新增各关学习内容
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:study:add')")
    @Log(title = "各关学习内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShashaStudy shashaStudy)
    {
        return toAjax(shashaStudyService.insertShashaStudy(shashaStudy));
    }

    /**
     * 修改各关学习内容
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:study:edit')")
    @Log(title = "各关学习内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShashaStudy shashaStudy)
    {
        return toAjax(shashaStudyService.updateShashaStudy(shashaStudy));
    }

    /**
     * 删除各关学习内容
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:study:remove')")
    @Log(title = "各关学习内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shashaStudyService.deleteShashaStudyByIds(ids));
    }


    /**
     * 获取学习题目
     *
     * @param levelId
     * @return com.jianbing.common.core.domain.AjaxResult
     * @author zheng
     * @create 2024/6/10
     **/

    //  @PreAuthorize("@ss.hasPermi('shasha:study:getStudy')")
    @Log(title = "各关学习内容", businessType = BusinessType.DELETE)
    @GetMapping("/studyId")
    public AjaxResult getStudy(@RequestParam("levelId") Integer levelId)
    {
        return success(shashaStudyService.getStudyQuesByLevelId(levelId));
    }
}
